Title: Setting up SMS in IRC, via BitlBee with purple-hangouts
Date: 2016-12-26 01:19
Category: IRC
Tags: IRC, CLI, VPS, IRCd, bitlbee, hangouts, weechat, tmux, pushover


**NOTE: It appears that this will cease to work as of 2021-01-27 according to a recent google email I received :'(**


###I've wanted this for so very long
Putting my texting into IRC, even if I don't send many messages, has long been a dream of mine.
Periodically I would look into solutions, and be disappointed.
This week I picked up the torch again and came across two options.
The first option is pretty hacky, but I'm going to bring it up for those who can't currently do the second, and to show that the second best solution still left a lot to be desired.


###Options
####<strike>GTalkSMS</strike>
[GTalkSMS] seemed like a ray of light when I found it.
And it does work... But it is hacky...

#####How does GTalkSMS work?

Well, it is an android app that monitors for incoming SMS messages (among a handful of other features).
The hackyness comes into play with how the SMS messages get to IRC.

GTalkSMS requires ***two*** jabber accounts -- each account listing the other as a friend.

* You feed GTalkSMS the server/port/user/pass for the first account, and it will then connect to jabber as that account.
* You teach it the name of the second account; this account will get notifications sent to it and be authorized to use 'commands'.

So it pretty much acts as a relay, and forces your phone to use battery to be connected to jabber.

**Note:** Getting to IRC at this point would involve connecting to ***just*** the second account in BitlBee. If You were connected to *both*, it would be spammy whenever you send a command to GTalkSMS... Which means you need a throwaway jabber account for this solution.

####So... What else can I find?
The above really didn't appeal to me, so I went back to researching.
After a while I came across [purple-hangouts], and found that it did in fact handle SMS.


####purple-hangouts
> Hangouts Plugin for libpurple  
> A replacement prpl for Hangouts in Pidgin/libpurple to support the proprietary protocol that Google uses for its Hangouts service. So far it supports all the fun things that aren't part of the XMPP interface, such as Group Chats, synchronised history between devices and SMS support via Google Voice.  

So, this can be used with [BitlBee], when it has been compiled to work with [libpurple].
This was music to my ears.

###Setup
####Installing Bitlbee
I'm going to fast forward through this step, as I already had a working BitlBee service running.
I did have to uninstall the `bitlbee` package, and replace it with `bitlbee-libpurpe`, on my Debian sid VPS.
This dropped right into place with the same config and non libpurple plugins ([bitlbee-facebook] and [bitlbee-steam]).
When restarting BitlBee, to make sure the update worked, I ran into a snafu I've had with Debian's BitlBee install.
Namely, it seems like the `systemd` implementation of the daemon is borked.
To enact a restart of BitlBee I have to manually kill the PIDs, as `service bitlbee stop` does not work.
Yes, I know `systemctl` is the current command, but `service` is pretty much an alias.
After killing the PIDs, I then `service bitlbee stop` and `service bitlbee start`.
I suspect it is still using `initd` type files.


####Installing purple-hangouts
On Debian, you will need the following dependencies: `libpurple-dev` `libjson-glib-dev` `libglib2.0-dev` `libprotobuf-c-dev` `protobuf-c-compiler` `mercurial` and `make`.
The [installation instructions] give a nice little code block for your copypasta pleasure, which I'll put below <sup>(using aptitude, as I prefer it)</sup>.

    :::bash
    sudo aptitude install libpurple-dev libjson-glib-dev libglib2.0-dev libprotobuf-c-dev protobuf-c-compiler mercurial make;
    hg clone https://bitbucket.org/EionRobb/purple-hangouts/ && cd purple-hangouts;
    make && sudo make install

Yes... this does force you to use `mercurial`... \**sigh*\*  
**Note:** EionRobb points out you can use `hg-git`, as well as downloading the source zip off of bitbucket.
I will have to give `hg-git` a try next time.

Anyway, installing was pretty easy, and I restarted BitlBee again to make sure it propagated.


####Configuring Google Voice and Google Fi
#####Google Voice
With a Google Voice set to use Hangouts, you are pretty much done.
Just make the Hangouts app your default SMS app.


####Google Fi
In addition to setting the Hangouts app to be the default, you will need to adjust a Fi specific setting.
From Google's [Using Hangouts with Project Fi] page:

> 1. On your phone, open the Hangouts app  
> 2. In the upper left corner, touch the Menu icon  
> 3. Touch Settings  
> 4. Touch the Google Account you use with Project Fi  
> 5. Under “Project Fi calls and SMS,” check the box next to “Messages” and confirm  


####Added account to BitlBee
At this point I removed my gtalk protocol account from BitlBee (`acc gtalk del`) and readded it as a hangouts protocol account, `acc add hangouts email@gmail.com`.  

After connecting (`acc hangouts on`) you will get a privmsg from `purple_request_0`:

> 2016-12-24 22:41:58     purple_request_0        Authorization Code  
> 2016-12-24 22:41:58     purple_request_0        URL_HERE  
> 2016-12-24 22:41:58     purple_request_0        Please follow the YouTube video to get the OAuth code  

I'll leave you to going through the video <sup>(link redacted, as it is a private youtube video)</sup>.
Once you have the oauth key, you paste it in and reply to `purple_request_0`.

And now your are connected!


####Fixing buddy nicks
At this point, you will notice that your buddies' nicks are messed up.
To fix this you will want to do `acc hangouts set nick_format %full_name`, and then `acc hangouts off`, followed by `acc hangouts on`, to refresh the nicks.
Don't forget to use the `save` command to be on the safe side.

**Note:** Alternatively, if you have pre-read these instructions, you could do this setting after adding the account and before connecting \**wink*\*


####Cell Phone Nicks
Unfortunately, at this point cell phones are not connected to the contact in purple-hangouts.
So if you have a friend named Alice who's number is 555-555-5555, you will have both `AliceAwesome` and `_155555555555`.
You can go through and `rename` the cell buddies to have a better nick with `rename _155555555555 AliceA_phone`.


###Done!
At this point you should be able to see sweet, sweet IRC side SMS messages!
I would like to thank Eion Robb and Mike 'Maiku' Ruprecht for making this beautiful tool.
I've been looking for something like this for **years**.

* ☑ Life Goal: SMS via IRC  
* ☐ Life Goal: Get all friends to use IRC


###Bonus Round
My personal IRC setup involves `tmux` with `WeeChat` running inside it 24/7/365.
With [WeeChat], I use `pushover.pl` <sup>(you can find it with the /script command)</sup> to send [pushover] notices to my phone on hilight/privmsg, when I am `/away`.
I then have my `/away` auto set by `screen_away.py` when I am detached from tmux, and not connected to my [weechat relay].

So, how to I stop my phone from making a bing sound twice, once for the SMS and once for pushover?
Since 99% of renamed cells have a default prefix ('**\_1**55555555555') <sup>(I'm assuming the '1', as I'm in the US)</sup>, and I use a standard convention when I set the nick ('name**\_phone**'), this is doable using `plugins.var.perl.pushover.blacklist`

    :::php
    /set plugins.var.perl.pushover.blacklist = "*_phone,_1*"

And then `/save` for good measure.


###Links
[GTalkSMS]  
[purple-hangouts]  
[BitlBee]  
[libpurple]  
[bitlbee-facebook]  
[bitlbee-steam]  
[installation instructions]  
[Using Hangouts with Project Fi]  
[WeeChat]  
[pushover]  
[weechat relay]  


[GTalkSMS]: https://play.google.com/store/apps/details?id=com.googlecode.gtalksms&hl=en
[purple-hangouts]: https://bitbucket.org/EionRobb/purple-hangouts/
[BitlBee]: https://www.bitlbee.org/main.php/news.r.html
[libpurple]: https://developer.pidgin.im/wiki/WhatIsLibpurple
[bitlbee-facebook]: https://github.com/bitlbee/bitlbee-facebook
[bitlbee-steam]: https://github.com/bitlbee/bitlbee-steam
[installation instructions]: https://bitbucket.org/EionRobb/purple-hangouts/overview
[Using Hangouts with Project Fi]: https://support.google.com/fi/answer/6188337?hl=en
[WeeChat]: https://weechat.org/
[pushover]: https://pushover.net/
[weechat relay]: https://weechat.org/files/doc/stable/weechat_user.en.html#relay_plugin
